Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: restore ability to disable color correct rendering #15898

Merged
merged 1 commit into from Dec 11, 2018

Conversation

poiru
Copy link
Contributor

@poiru poiru commented Nov 30, 2018

In Electron 2.0, --disable-features=ColorCorrectRendering could be
used to make the app use the display color space (e.g. P3 on Macs)
instead of color correcting to sRGB. Because color correct rendering is
always enabled on Chromium 62 and later and because
--force-color-profile has no effect on macOS, apps that need e.g. P3
colors are currently stuck on Electron 2.0.

This restores the functionality removed in
https://chromium-review.googlesource.com/698347 in the form of the
--disable-color-correct-rendering switch.

This can be removed once web content (including WebGL) learn how
to deal with color spaces. That is being tracked at
https://crbug.com/634542 and https://crbug.com/711107.

As an example of a widely used app using
--disable-features=ColorCorrectRendering, see VSCode:
https://github.com/Microsoft/vscode/blob/3f33ef2593d3efe6eca5230f3d34d3406fb73498/src/main.js#L138-L139

Notes: Add --disable-color-correct-rendering switch

@poiru
Copy link
Contributor Author

poiru commented Nov 30, 2018

I confirmed that #FF0000 with disable-color-correct-rendering are more saturated on a Mac with a P3 display. I checked colors generated with WebGL, CSS, and a PNG image. Here's the code:

main.js:

const { app, BrowserWindow } = require('electron');

app.commandLine.appendSwitch('disable-color-correct-rendering');

let win = null;

app.once('ready', () => {
  win = new BrowserWindow({
    width: 300,
    height: 600,
    webPreferences: {
      nodeIntegration: false
    }
  });

  win.loadURL(`file://${__dirname}/test.html`);
});

test.html:

<html>
<head>
  <meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'; img-src 'self' data:">
  <style>
  body, html {
    width: 100%;
    height: 100%;
    font-family: sans-serif;
    font-size: 10px;
  }
  canvas, div, img {
    width: 100px;
    height: 100px;
    border: 2px solid black;
  }
  </style>
</head>
<body>
  <p>webgl canvas</p>
  <canvas></canvas>
  <p>css</p>
  <div style="background-color: red"></div>
  <p>img</p>
  <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/AAAZ4gk3AAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg=="/>
  <p id="ua"></p>
</body>
<script>
window.addEventListener('load', () => {
  var canvas = document.querySelector('canvas');
  var gl = canvas.getContext('webgl');
  gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  gl.clearColor(1.0, 0.0, 0.0, 1.0);
  gl.clear(gl.COLOR_BUFFER_BIT);

  document.querySelector('#ua').innerHTML = navigator.userAgent;
}, false);
</script>

@poiru poiru force-pushed the disable-color-correct-rendering branch from 8a88557 to fd56b87 Compare December 3, 2018 20:10
Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is far from clear to me that this patches all the necessary places, and I'm concerned about continuing support for this flag in the face of future upstream refactors in Chrome's rendering code, but I'm satisfied that at least for this particular version of Chrome that this patch does not change behaviour unless you pass the flag, so I'm approving anyway.

Please be prepared for this flag to get disabled in a future chrome upgrade if you're not around to help port it :)

RendererSettings renderer_settings;
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+ renderer_settings.enable_color_correct_rendering =
+ !command_line->HasSwitch("disable-color-correct-rendering");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a string constant kDisableColorCorrectRendering so that typos will be a compile error :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

In Electron 2.0, `--disable-features=ColorCorrectRendering` could be
used to make the app use the display color space (e.g. P3 on Macs)
instead of color correcting to sRGB. Because color correct rendering is
always enabled on Chromium 62 and later and because
`--force-color-profile` has no effect on macOS, apps that need e.g. P3
colors are currently stuck on Electron 2.0.

This restores the functionality removed in
https://chromium-review.googlesource.com/698347 in the form of the
`--disable-color-correct-rendering` switch.

This can be removed once web content (including WebGL) learn how
to deal with color spaces. That is being tracked at
https://crbug.com/634542 and https://crbug.com/711107.

As an example of a widely used app using
`--disable-features=ColorCorrectRendering`, see VSCode:
https://github.com/Microsoft/vscode/blob/3f33ef2593d3efe6eca5230f3d34d3406fb73498/src/main.js#L138-L139

Notes: Add `--disable-color-correct-rendering` switch
@poiru poiru force-pushed the disable-color-correct-rendering branch from fd56b87 to 3af9274 Compare December 11, 2018 12:01
@deepak1556 deepak1556 merged commit e383aa3 into master Dec 11, 2018
@release-clerk
Copy link

release-clerk bot commented Dec 11, 2018

Release Notes Persisted

Add --disable-color-correct-rendering switch

@deepak1556 deepak1556 deleted the disable-color-correct-rendering branch December 11, 2018 16:06
@trop
Copy link
Contributor

trop bot commented Dec 11, 2018

I was unable to backport this PR to "3-1-x" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Contributor

trop bot commented Dec 11, 2018

I was unable to backport this PR to "4-0-x" cleanly;
you will need to perform this backport manually.

poiru added a commit that referenced this pull request Dec 11, 2018
…0-x)

Backport of #15898

See that PR for details.

Notes: Add `--disable-color-correct-rendering` switch
ckerr pushed a commit that referenced this pull request Dec 11, 2018
…0-x) (#16020)

Backport of #15898

See that PR for details.

Notes: Add `--disable-color-correct-rendering` switch
@bpasero
Copy link
Contributor

bpasero commented Jan 4, 2019

@poiru did this ever land on 3-0-x?

poiru added a commit to poiru/electron that referenced this pull request Sep 27, 2019
This broke in Electron 6 due to some Chromium changes.

Test Plan:

- Confirm that test case from
  electron#15898 (comment)
  now works

Notes: Fix disabling color correct rendering with `--disable-color-correct-rendering`
nornagon pushed a commit that referenced this pull request Sep 30, 2019
…20356)

This broke in Electron 6 due to some Chromium changes.

Test Plan:

- Confirm that test case from
  #15898 (comment)
  now works

Notes: Fix disabling color correct rendering with `--disable-color-correct-rendering`
poiru added a commit to poiru/electron that referenced this pull request May 27, 2020
This regressed once again in Electron 8 due to Chromium changes.

Test Plan:

- Confirm that test case from electron#15898 (comment) now works

Notes: Fix disabling color correct rendering with `--disable-color-correct-rendering`
zcbenz pushed a commit that referenced this pull request Jun 2, 2020
…23787)

This regressed once again in Electron 8 due to Chromium changes.

Test Plan:

- Confirm that test case from #15898 (comment) now works

Notes: Fix disabling color correct rendering with `--disable-color-correct-rendering`
trop bot pushed a commit that referenced this pull request Jun 2, 2020
This regressed once again in Electron 8 due to Chromium changes.

Test Plan:

- Confirm that test case from #15898 (comment) now works

Notes: Fix disabling color correct rendering with `--disable-color-correct-rendering`
trop bot pushed a commit that referenced this pull request Jun 2, 2020
This regressed once again in Electron 8 due to Chromium changes.

Test Plan:

- Confirm that test case from #15898 (comment) now works

Notes: Fix disabling color correct rendering with `--disable-color-correct-rendering`
jkleinsc pushed a commit that referenced this pull request Jun 2, 2020
…23899)

This regressed once again in Electron 8 due to Chromium changes.

Test Plan:

- Confirm that test case from #15898 (comment) now works

Notes: Fix disabling color correct rendering with `--disable-color-correct-rendering`

Co-authored-by: Biru Mohanathas <birunthan@mohanathas.com>
codebytere pushed a commit that referenced this pull request Jun 3, 2020
…23900)

* fix: Make the `--disable-color-correct-rendering` switch work again

This regressed once again in Electron 8 due to Chromium changes.

Test Plan:

- Confirm that test case from #15898 (comment) now works

Notes: Fix disabling color correct rendering with `--disable-color-correct-rendering`

* update patches

Co-authored-by: Biru Mohanathas <birunthan@mohanathas.com>
Co-authored-by: Electron Bot <anonymous@electronjs.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants